﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using MaxStudio.Concrete.Web;
using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server;
using MaxStudio.Concrete.Server.Service;
using MaxStudio.Concrete.Server.Dao;
using System.Configuration;


namespace MaxStudio.Concrete.Web.Pages
{
    public partial class RPTCementReview : BasePage
    {
        string wholSequence = "LT/S实-12-01";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindGridView();
            }
        }
        #region Private Method

        private void BindGridView()
        {
            RPTCementReviewService RPTCementReviewServiceObj = ServiceFactory.getRPTCementReviewService();
            OperationResult<List<tb_RPT_CementReview>> result = RPTCementReviewServiceObj.GetAllCementReview();

            if (result.operationSuccess)
            {
                gvCementReviewList.DataSource = result.obj;
                gvCementReviewList.DataBind();
            }
            else
            {
                //EXCEPTION
                //return null;
            }
        }

        private void BindEdieDialog(int id)
        {
            RPTCementReviewService RPTCementReviewServiceObj = ServiceFactory.getRPTCementReviewService();
            OperationResult<tb_RPT_CementReview> resultEdit = RPTCementReviewServiceObj.GetCementReviewById(id); 

            if (resultEdit.operationSuccess == true)
            {  
                txtEditProjectName.Text = resultEdit.obj.ProjectName;
                txtEditProdCode.Text = resultEdit.obj.ProdCode;
                txtEditFactoryNumbers.Text = resultEdit.obj.FactoryNumbers;
                txtEditIntoFactoryDate.Text = resultEdit.obj.IntoFactoryDate;
                txtEditTestDate.Text = resultEdit.obj.TestDate;
                txtEditSTANStandardConsistency.Text = resultEdit.obj.STANStandardConsistency;
                txtEditSTANSpecSurfaceArea.Text = resultEdit.obj.STANSpecSurfaceArea;
                txtEditSTANScreenResidue.Text = resultEdit.obj.STANScreenResidue;
                txtEditSTANCakeMethod.Text = resultEdit.obj.STANCakeMethod;
                txtEditSTANLeiMethod.Text = resultEdit.obj.STANLeiMethod;
                txtEditSTANInitialSet.Text = resultEdit.obj.STANInitialSet;
                txtEditSTANFinalSet.Text = resultEdit.obj.STANFinalSet;
                txtEditSTANAveBendingStrength3D.Text = resultEdit.obj.STANAveBendingStrength3D;
                txtEditSTANAveBendingStrength28D.Text = resultEdit.obj.STANAveBendingStrength28D;
                txtEditSTANAveCompressiveStrength3D.Text = resultEdit.obj.STANAveCompressiveStrength3D;
                txtEditSTANAveCompressiveStrength28D.Text = resultEdit.obj.STANAveCompressiveStrength28D;
                txtEditMEASUStandardConsistency.Text = resultEdit.obj.MEASUStandardConsistency;
                txtEditMEASUSpecSurfaceArea.Text = resultEdit.obj.MEASUSpecSurfaceArea;
                txtEditMEASUScreenResidue.Text = resultEdit.obj.MEASUScreenResidue;
                txtEditMEASUCakeMethod.Text = resultEdit.obj.MEASUCakeMethod;
                txtEditMEASULeiMethod.Text = resultEdit.obj.MEASULeiMethod;
                txtEditMEASUInitialSet.Text = resultEdit.obj.MEASUInitialSet;
                txtEditMEASUFinalSet.Text = resultEdit.obj.MEASUFinalSet;
                txtEditMEASUAveBendingStrength3D.Text = resultEdit.obj.MEASUAveBendingStrength3D;
                txtEditMEASUAveBendingStrength28D.Text = resultEdit.obj.MEASUAveBendingStrength28D;
                txtEditMEASUAveCompressiveStrength3D.Text = resultEdit.obj.MEASUAveCompressiveStrength3D;
                txtEditMEASUAveCompressiveStrength28D.Text = resultEdit.obj.MEASUAveCompressiveStrength28D;
                txtEditTestStandard.Text = resultEdit.obj.TestStandard;
                txtEditTestResult.Text = resultEdit.obj.TestResult;
                txtEditRemark.Text = resultEdit.obj.Remark;
                txtEditReview.Text = resultEdit.obj.Review;
                txtEditApproval.Text = resultEdit.obj.Approval;
                txtEditTest.Text = resultEdit.obj.Test;

                lbLastModier.Text = "TEST";
                lbEidtId.Text = resultEdit.obj.Id.ToString();
                lbLastModifyDate.Text = resultEdit.obj.ModifyDate.ToShortDateString();
            }
        }

        private void DeleteRecords(int id)
        {
            lbDeleteId.Text = id.ToString();
        }

        #endregion

        #region Event

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            RPTCementReviewService RPTCementReviewServiceObj = ServiceFactory.getRPTCementReviewService(); 
             tb_RPT_CementReview instance = new tb_RPT_CementReview(); 
            instance.Sequence = wholSequence; 
            instance.ProjectName=txtProjectName.Text;
            instance.ProdCode=txtProdCode.Text;
            instance.FactoryNumbers=txtFactoryNumbers.Text;
            instance.IntoFactoryDate=txtIntoFactoryDate.Text;
            instance.TestDate=txtTestDate.Text;
            instance.STANStandardConsistency=txtSTANStandardConsistency.Text;
            instance.STANSpecSurfaceArea=txtSTANSpecSurfaceArea.Text;
            instance.STANScreenResidue=txtSTANScreenResidue.Text;
            instance.STANCakeMethod=txtSTANCakeMethod.Text;
            instance.STANLeiMethod=txtSTANLeiMethod.Text;
            instance.STANInitialSet=txtSTANInitialSet.Text;
            instance.STANFinalSet=txtSTANFinalSet.Text;
            instance.STANAveBendingStrength3D=txtSTANAveBendingStrength3D.Text;
            instance.STANAveBendingStrength28D=txtSTANAveBendingStrength28D.Text;
            instance.STANAveCompressiveStrength3D=txtSTANAveCompressiveStrength3D.Text;
            instance.STANAveCompressiveStrength28D=txtSTANAveCompressiveStrength28D.Text;
            instance.MEASUStandardConsistency=txtMEASUStandardConsistency.Text;
            instance.MEASUSpecSurfaceArea=txtMEASUSpecSurfaceArea.Text;
            instance.MEASUScreenResidue=txtMEASUScreenResidue.Text;
            instance.MEASUCakeMethod=txtMEASUCakeMethod.Text;
            instance.MEASULeiMethod=txtMEASULeiMethod.Text;
            instance.MEASUInitialSet=txtMEASUInitialSet.Text;
            instance.MEASUFinalSet=txtMEASUFinalSet.Text;
            instance.MEASUAveBendingStrength3D=txtMEASUAveBendingStrength3D.Text;
            instance.MEASUAveBendingStrength28D=txtMEASUAveBendingStrength28D.Text;
            instance.MEASUAveCompressiveStrength3D=txtMEASUAveCompressiveStrength3D.Text;
            instance.MEASUAveCompressiveStrength28D=txtMEASUAveCompressiveStrength28D.Text;
            instance.TestStandard=txtTestStandard.Text;
            instance.TestResult=txtTestResult.Text;
            instance.Remark=txtRemark.Text;
            instance.Review=txtReview.Text;
            instance.Approval=txtApproval.Text;
            instance.Test = txtTest.Text; 

            OperationResult<tb_RPT_CementReview> result = RPTCementReviewServiceObj.CreateCementReview(instance);
            BindGridView();

        }
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            int editId = 0;
            if (lbEidtId.Text.Length > 0)
            {
                editId = Int32.Parse(lbEidtId.Text);
            }

            RPTCementReviewService RPTCementReviewServiceObj = ServiceFactory.getRPTCementReviewService();
            tb_RPT_CementReview entity = new tb_RPT_CementReview();

            entity.Id = editId;
            entity.Sequence = wholSequence; 
            entity.ProjectName = txtEditProjectName.Text;
            entity.ProdCode = txtEditProdCode.Text;
            entity.FactoryNumbers = txtEditFactoryNumbers.Text;
            entity.IntoFactoryDate = txtEditIntoFactoryDate.Text;
            entity.TestDate = txtEditTestDate.Text;
            entity.STANStandardConsistency = txtEditSTANStandardConsistency.Text;
            entity.STANSpecSurfaceArea = txtEditSTANSpecSurfaceArea.Text;
            entity.STANScreenResidue = txtEditSTANScreenResidue.Text;
            entity.STANCakeMethod = txtEditSTANCakeMethod.Text;
            entity.STANLeiMethod = txtEditSTANLeiMethod.Text;
            entity.STANInitialSet = txtEditSTANInitialSet.Text;
            entity.STANFinalSet = txtEditSTANFinalSet.Text;
            entity.STANAveBendingStrength3D = txtEditSTANAveBendingStrength3D.Text;
            entity.STANAveBendingStrength28D = txtEditSTANAveBendingStrength28D.Text;
            entity.STANAveCompressiveStrength3D = txtEditSTANAveCompressiveStrength3D.Text;
            entity.STANAveCompressiveStrength28D = txtEditSTANAveCompressiveStrength28D.Text;
            entity.MEASUStandardConsistency = txtEditMEASUStandardConsistency.Text;
            entity.MEASUSpecSurfaceArea = txtEditMEASUSpecSurfaceArea.Text;
            entity.MEASUScreenResidue = txtEditMEASUScreenResidue.Text;
            entity.MEASUCakeMethod = txtEditMEASUCakeMethod.Text;
            entity.MEASULeiMethod = txtEditMEASULeiMethod.Text;
            entity.MEASUInitialSet = txtEditMEASUInitialSet.Text;
            entity.MEASUFinalSet = txtEditMEASUFinalSet.Text;
            entity.MEASUAveBendingStrength3D = txtEditMEASUAveBendingStrength3D.Text;
            entity.MEASUAveBendingStrength28D = txtEditMEASUAveBendingStrength28D.Text;
            entity.MEASUAveCompressiveStrength3D = txtEditMEASUAveCompressiveStrength3D.Text;
            entity.MEASUAveCompressiveStrength28D = txtEditMEASUAveCompressiveStrength28D.Text;
            entity.TestStandard = txtEditTestStandard.Text;
            entity.TestResult = txtEditTestResult.Text;
            entity.Remark = txtEditRemark.Text;
            entity.Review = txtEditReview.Text;
            entity.Approval = txtEditApproval.Text;
            entity.Test = txtEditTest.Text;  


            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            entity.CreateDate = DateTime.Now;

            OperationResult<tb_RPT_CementReview> resultEdit = RPTCementReviewServiceObj.ModifyCementReview(entity);

            BindGridView();
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int deleteId = Int32.Parse(lbDeleteId.Text);
            RPTCementReviewService RPTCementReviewServiceObj = ServiceFactory.getRPTCementReviewService();
            tb_RPT_CementReview deleteEntity = new tb_RPT_CementReview();

            deleteEntity.Id = deleteId;
            RPTCementReviewServiceObj.DeleteCementReview(deleteEntity);

            BindGridView();
        }

        protected void gvCementReviewList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                string strSelectId = e.CommandArgument.ToString();
                BindEdieDialog(Int32.Parse(strSelectId));
            }

            if (e.CommandName == "del")
            {
                string strSelectId = e.CommandArgument.ToString();
                DeleteRecords(Int32.Parse(strSelectId));
            }
        }

        protected void gvCementReviewList_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvCementReviewList.PageIndex = e.NewPageIndex;
            BindGridView();
        }
        #endregion
    }
}
